package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysProvCityDist;
import com.ruoyi.system.service.ISysProvCityDistService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 省市县字典Controller
 * 
 * @author rey
 * @date 2022-10-25
 */
@RestController
@RequestMapping("/system/dist")
public class SysProvCityDistController extends BaseController
{
    @Autowired
    private ISysProvCityDistService sysProvCityDistService;

    /**
     * 查询省市县字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:dist:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysProvCityDist sysProvCityDist)
    {
        startPage();
        List<SysProvCityDist> list = sysProvCityDistService.selectSysProvCityDistList(sysProvCityDist);
        return getDataTable(list);
    }

    /**
     * 导出省市县字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:dist:export')")
    @Log(title = "省市县字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysProvCityDist sysProvCityDist)
    {
        List<SysProvCityDist> list = sysProvCityDistService.selectSysProvCityDistList(sysProvCityDist);
        ExcelUtil<SysProvCityDist> util = new ExcelUtil<SysProvCityDist>(SysProvCityDist.class);
        util.exportExcel(response, list, "省市县字典数据");
    }

    /**
     * 获取省市县字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysProvCityDistService.selectSysProvCityDistById(id));
    }

    /**
     * 新增省市县字典
     */
    @PreAuthorize("@ss.hasPermi('system:dist:add')")
    @Log(title = "省市县字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysProvCityDist sysProvCityDist)
    {
        return toAjax(sysProvCityDistService.insertSysProvCityDist(sysProvCityDist));
    }

    /**
     * 修改省市县字典
     */
    @PreAuthorize("@ss.hasPermi('system:dist:edit')")
    @Log(title = "省市县字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysProvCityDist sysProvCityDist)
    {
        return toAjax(sysProvCityDistService.updateSysProvCityDist(sysProvCityDist));
    }

    /**
     * 删除省市县字典
     */
    @PreAuthorize("@ss.hasPermi('system:dist:remove')")
    @Log(title = "省市县字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysProvCityDistService.deleteSysProvCityDistByIds(ids));
    }
}
